const express = require('express');
const router = express.Router();
const { auth, teacherAuth, optionalAuth } = require('../middleware/auth');
const {
  getResources,
  getResourceById,
  createResource,
  updateResource,
  deleteResource,
  likeResource,
  getResourceStats
} = require('../controllers/resourceController');

// 获取资源列表（公开接口）
router.get('/', optionalAuth, getResources);

// 获取资源统计
router.get('/stats', getResourceStats);

// 获取资源详情
router.get('/:id', optionalAuth, getResourceById);

// 创建资源（需要教师权限）
router.post('/', auth, teacherAuth, createResource);

// 更新资源
router.put('/:id', auth, updateResource);

// 删除资源
router.delete('/:id', auth, deleteResource);

// 点赞资源
router.post('/:id/like', auth, likeResource);

module.exports = router; 